package com.dd.stack.es.pojo.es;

import com.dd.stack.common.util.annotation.Explanation;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.io.Serializable;
import java.time.Instant;
import java.util.List;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/4/18 11:37
 * @Description 电商复杂ElasticSearch数据 模拟测试
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("Ecommerce产品ESDO -> @Document注解指定该实体类对应的Elasticsearch索引名称为ecommerce_products_java")
@Document(indexName = "ecommerce_products_java")
public class EcommerceProductESDO implements Serializable {
    @Id
    @Explanation("Elasticsearch自动生成的文档ID")
    private String id;
    @Field(type = FieldType.Keyword)
    @Explanation("产品唯一标识符，业务主键")
    private String productId;
    @Field(type = FieldType.Text)
    @Explanation("产品名称，支持全文检索")
    private String name;
    @Field(type = FieldType.Text)
    @Explanation("产品详细描述，支持全文检索")
    private String description;
    @Field(type = FieldType.Double)
    @Explanation("产品销售价格，单位：元")
    private Double price;
    @Field(type = FieldType.Double)
    @Explanation("产品成本价，单位：元")
    private Double cost;
    @Field(type = FieldType.Double)
    @Explanation("折扣率，取值范围0-1")
    private Double discount;
    @Field(type = FieldType.Integer)
    @Explanation("当前库存数量")
    private Integer stock;
    @Field(type = FieldType.Boolean)
    @Explanation("是否上架销售")
    private Boolean isActive;
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second_millis)
    @Explanation("产品创建时间，ISO8601格式")
    private Instant createdAt;
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second_millis)
    @Explanation("产品最后更新时间，ISO8601格式")
    private Instant updatedAt;
    @Field(type = FieldType.Keyword)
    @Explanation("产品所属分类列表")
    private List<String> categories;
    @Field(type = FieldType.Keyword)
    @Explanation("产品标签列表")
    private List<String> tags;
    @Field(type = FieldType.Nested)
    @Explanation("产品自定义属性列表")
    private List<ProductAttribute> attributes;
    @Field(type = FieldType.Nested)
    @Explanation("产品规格参数分组列表")
    private List<SpecificationGroup> specifications;
    @Field(type = FieldType.Nested)
    @Explanation("用户评价列表")
    private List<ProductReview> reviews;
    @Field(type = FieldType.Object)
    @Explanation("产品销售统计数据")
    private SalesData salesData;
    @GeoPointField
    @Explanation("产品地理位置坐标，格式：纬度,经度")
    private String location;
    @Field(type = FieldType.Double)
    @Explanation("产品重量，单位：千克")
    private Double weight;
    @Field(type = FieldType.Object)
    @Explanation("产品尺寸信息")
    private ProductDimensions dimensions;
    @Field(type = FieldType.Object)
    @Explanation("制造商信息")
    private Manufacturer manufacturer;
    @Field(type = FieldType.Nested)
    @Explanation("产品变体列表（如不同颜色/尺寸）")
    private List<ProductVariant> variants;

    // 内部类定义
    @Data
    @Explanation("产品自定义属性")
    public static class ProductAttribute {
        @Field(type = FieldType.Boolean)
        @Explanation("是否对用户可见")
        private Boolean isVisible;
        @Field(type = FieldType.Keyword)
        @Explanation("属性名称")
        private String name;
        @Field(type = FieldType.Text)
        @Explanation("属性值")
        private String value;
    }

    @Data
    @Explanation("产品规格参数分组")
    public static class SpecificationGroup {
        @Field(type = FieldType.Keyword)
        @Explanation("规格分组名称")
        private String group;
        @Field(type = FieldType.Nested)
        @Explanation("规格项列表")
        private List<SpecItem> items;
    }

    @Data
    @Explanation("规格参数项")
    public static class SpecItem {
        @Field(type = FieldType.Keyword)
        @Explanation("规格键名")
        private String key;
        @Field(type = FieldType.Text)
        @Explanation("规格值")
        private String value;
    }

    @Data
    @Explanation("用户评价")
    public static class ProductReview {
        @Field(type = FieldType.Keyword)
        @Explanation("用户ID")
        private String userId;
        @Field(type = FieldType.Integer)
        @Explanation("评分（1-5星）")
        private Integer rating;
        @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second_millis)
        @Explanation("评价时间")
        private Instant createdAt;
        @Field(type = FieldType.Text)
        @Explanation("评价内容")
        private String comment;
        @Field(type = FieldType.Integer)
        @Explanation("有用数")
        private Integer helpfulCount;
        @Field(type = FieldType.Boolean)
        @Explanation("是否已验证购买")
        private Boolean isVerified;
        @Field(type = FieldType.Keyword)
        @Explanation("用户名")
        private String username;
    }

    @Data
    @Explanation("销售统计数据")
    public static class SalesData {
        @Field(type = FieldType.Integer)
        @Explanation("总销量")
        private Integer total;
        @Field(type = FieldType.Double)
        @Explanation("退货率")
        private Double returnRate;
        @Field(type = FieldType.Integer)
        @Explanation("最近30天销量")
        private Integer last30Days;
    }

    @Data
    @Explanation("产品尺寸信息")
    public static class ProductDimensions {
        @Field(type = FieldType.Keyword)
        @Explanation("尺寸单位")
        private String unit;
        @Field(type = FieldType.Double)
        @Explanation("长度")
        private Double length;
        @Field(type = FieldType.Double)
        @Explanation("宽度")
        private Double width;
        @Field(type = FieldType.Double)
        @Explanation("高度")
        private Double height;
    }

    @Data
    @Explanation("制造商信息")
    public static class Manufacturer {
        @Field(type = FieldType.Keyword)
        @Explanation("国家")
        private String country;
        @Field(type = FieldType.Integer)
        @Explanation("成立年份")
        private Integer foundedYear;
        @Field(type = FieldType.Keyword)
        @Explanation("制造商名称")
        private String name;
    }

    @Data
    @Explanation("产品变体信息")
    public static class ProductVariant {
        @Field(type = FieldType.Keyword)
        @Explanation("颜色")
        private String color;
        @Field(type = FieldType.Keyword)
        @Explanation("尺寸")
        private String size;
        @Field(type = FieldType.Double)
        @Explanation("价格差异（相对于基准价格）")
        private Double priceDiff;
        @Field(type = FieldType.Keyword)
        @Explanation("库存单位编码")
        private String sku;
        @Field(type = FieldType.Integer)
        @Explanation("该变体库存数量")
        private Integer stock;
    }
}